package com.example.mybatisplus.web.controller;

import com.example.mybatisplus.model.domain.Admins;
import com.example.mybatisplus.model.dto.LogDTO;
import com.example.mybatisplus.model.dto.SelectRequest;
import com.example.mybatisplus.model.dto.TimeRangeRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.LogsService;
import com.example.mybatisplus.model.domain.Logs;

import java.time.LocalDateTime;
import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-07-17
 * @version v1.0
 */
@Controller
@RequestMapping("/api/logs")
public class LogsController {

    private final Logger logger = LoggerFactory.getLogger( LogsController.class );

    @Autowired
    private LogsService logsService;

    @GetMapping("/getAll")
    @ResponseBody
    public JsonResponse<List<LogDTO>> getAllLogs() {
        try {
            List<LogDTO> logsList = logsService.getAllLogs();
            return JsonResponse.success(logsList, "获取成功");
        } catch (Exception e) {
            logger.error("获取违纪记录失败", e);
            return JsonResponse.message(false, 500, "获取失败");
        }
    }

    @PostMapping("/select")
    @ResponseBody
    public JsonResponse<List<LogDTO>> select(@RequestBody SelectRequest request) {
        try {
//            String stuId = request.getStuId();
//            String stuName = request.getStuName();
//            String operatorId = request.getOperatorId();
//            String operatorName = request.getOperatorName();
//            String operationType = request.getOperationType();
//            LocalDateTime startTime = request.getStartTime();
//            LocalDateTime endTime = request.getEndTime();

            List<LogDTO> logsList = logsService.select(request);
            return JsonResponse.success(logsList, "获取成功");
        } catch (Exception e) {
            logger.error("获取违纪记录失败", e);
            return JsonResponse.message(false, 500, "获取失败");
        }
    }


}

